package cn.tedu.aop.article.controller;

import cn.tedu.aop.article.pojo.Article;
import cn.tedu.aop.article.service.ArticleService;
import cn.tedu.aop.base.response.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/")
public class ArticleController {
    @Autowired
    private ArticleService articleService;
    @DeleteMapping("/articles")
    public JsonResult deleteById(@RequestBody Long[] ids){
        System.out.println("ArticleController.thread.name->"+Thread.currentThread().getName());
        articleService.deleteById(ids);
        return new JsonResult(200,"delete ok");
    }
    @PostMapping("/articles")
    public JsonResult save(@RequestBody @Validated Article article){
        articleService.save(article);
        return new JsonResult(200,"save ok");
    }
    @GetMapping("/articles/{id}")
    public JsonResult selectById(@PathVariable("id") Long id){
        Article article = articleService.selectById(id);
        return new JsonResult(article);
    }

}
